package com.tools.cleanmaster.ui.card;

import android.app.Activity;
import android.text.Html;
import android.view.View;
import android.widget.Toast;

import com.tools.ad.EntranceType;
import com.tools.ad.util.GARecordUtils;
import com.tools.cleanmaster.CleanApplication;
import com.tools.cleanmaster.CleanGAConstant;
import com.tools.cleanmaster.R;
import com.tools.cleanmaster.ui.card.factory.CardListAdapter;
import com.tools.cleanmaster.ui.card.viewholder.ACardViewHolder;
import com.tools.cleanmaster.ui.card.viewholder.CommonCardViewHolder;
import com.tools.cleanmaster.ui.view.ToastHelper;


public class ChargingCardItem extends ACardItem {

    public ChargingCardItem(EntranceType entranceType, int pos) {
        super(entranceType, pos);
    }

    @Override
    public CardViewType getCardViewType() {
        return CardViewType.CHARGING;
    }

    @Override
    public boolean needShow(EntranceType entranceType) {
        return !imContext.getCleanSharedPrefManager().getChargingEnable();
    }

    @Override
    public String getCardName() {
        return CardType.CHARGING.key;
    }

    @Override
    public void bindCardView(final Activity activity, ACardViewHolder viewHolder, final CardListAdapter cardAdapter, final int position) {
        super.bindCardView(activity, viewHolder, cardAdapter, position);
        CommonCardViewHolder holder = (CommonCardViewHolder) viewHolder;
        holder.mLogo.setImageResource(R.drawable.card_func_charging);
        holder.mTitle.setText(R.string.charge_status_title);
        holder.mDesc.setText(Html.fromHtml(activity.getString(R.string.charge_status_content)));
        holder.mExecute.setText(R.string.screen_card_btn_txt);
        holder.mExecute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doClick(activity, cardAdapter, position);
            }
        });
        holder.mItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doClick(activity, cardAdapter, position);
            }
        });

    }

    private void doClick(Activity activity, CardListAdapter adapter, int position) {
        imContext.getCleanSharedPrefManager().setChargingEnable(true);
        ToastHelper.create(CleanApplication.getInstance(), activity.getString(R.string.charge_status_enable_toast), Toast.LENGTH_LONG).show();
        adapter.dismissAnimation(position);

        GARecordUtils.report(imContext, CleanGAConstant.C_FUNC, CleanGAConstant.A_CLICK, CleanGAConstant.L_CARD_SMART_CHARGING);
    }
}
